function list_iter (t)
    local i = 0
    local max = table.getn(t)
    return function()
        i = i+1
        if i <= max then return t[i] end   
    end
end

list= {'foo','bar','zzz'}

-- while
iter = list_iter(list)
while true do
    local ele = iter()
    if ele == nil then break end
    print(ele) 
end

-- for 
for ele in list_iter(list) do
    print(ele)
end

-- pairs
for k,v in pairs(list) do 
    print (k,v)
end

-- ipairs
for k,v in ipairs(list) do 
    print (k,v)
end